<template>
  <section class="staffList">
    <!--工具条-->
    <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
      <el-form :inline="true" :model="filters">
        <el-form-item>
          <el-input v-model="filters.staffName" placeholder="请输入员工姓名"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" v-on:click="findList">查询</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" v-on:click="addCompany">新增</el-button>
        </el-form-item>
      </el-form>
    </el-col>
    <!--列表-->
    <el-table
      :data="list"
      highlight-current-row
      v-loading="listLoading"
      style="width: 100%;"
      height="70vh"
    >
      <el-table-column prop="staffCode" label="员工编码" align="center"></el-table-column>
      <el-table-column prop="staffName" label="员工姓名" align="center"></el-table-column>
      <el-table-column prop="companyName" label="公司名称" align="center"></el-table-column>
      <el-table-column prop="departmentName" label="部门名称" align="center"></el-table-column>
      <el-table-column prop="postName" label="职位" align="center"></el-table-column>
      <el-table-column prop="staffPhone" label="手机号" align="center"></el-table-column>
      <el-table-column label="性别" align="center">
        <template slot-scope="scope">
          <el-tag
            :type="scope.row.staffSex == '1' ? 'primary' : 'success'"
            disable-transitions
          >{{scope.row.staffSex==1?'男':'女'}}</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="createTime" label="创建时间" align="center" width="150"></el-table-column>
      <el-table-column prop="createUser" label="创建人" align="center"></el-table-column>
      <el-table-column prop="description" label="描述" align="center"></el-table-column>
      <el-table-column prop="updateTime" label="更新时间" align="center" width="150"></el-table-column>
      <el-table-column prop="updateUser" label="更新人员" align="center"></el-table-column>
      <el-table-column label="离职状态" align="center">
        <template slot-scope="scope">
          <el-tag
            :type="scope.row.quitStatus == '1' ? 'success' : 'danger'"
            disable-transitions
          >{{scope.row.quitStatus==1?'在职':'离职'}}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="150" align="center">
        <template slot-scope="scope">
          <el-button size="small" @click="handDelete(scope.row)">删除</el-button>
          <el-button type="danger" size="small" @click="handEdit(scope.row)">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-col :span="24" class="toolbar">
      <!-- <el-button type="danger" @click="batchRemove" :disabled="this.sels.length===0">批量删除</el-button> -->
      <el-pagination
        layout="prev, pager, next"
        @current-change="handleCurrentChange"
        :page-size="20"
        :total="total"
        style="float:right;"
      ></el-pagination>
    </el-col>
    <!--新增 编辑界面-->
    <el-dialog
      :top="'30px'"
      title="员工"
      :visible.sync="addFormVisible"
      :close-on-click-modal="false"
    >
      <addStaff @hideTotas="hideTotas" v-if="addFormVisible" :sendFormData="sendFormData"></addStaff>
    </el-dialog>
  </section>
</template>

<script>
import addStaff from "./components/addStaff";

import { staffList, staffDelete } from "../../api/baseSetting";

export default {
  data() {
    return {
      filters: {
        staffName: ""
      },
      addFormVisible: false,
      list: [],
      total: 0,
      page: 1,
      listLoading: false,
      sendFormData: {
        //点中的参数
      }
    };
  },
  components: {
    addStaff
  },
  methods: {
    //点击删除
    handDelete(e) {
      console.log(e);
      let staffId = e.staffId;
      this.$confirm("确认删除该员工", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          staffDelete([staffId]).then(res => {
            this.$message({
              type: "success",
              message: "删除成功!"
            });
            this.filters.staffName = "";
            this.page = 1;
            this.getList();
          });
        })
        .catch(() => {});
    },
    //点击编辑
    handEdit(detail) {
      this.sendFormData = detail;
      this.addFormVisible = true;
    },
    //分页
    handleCurrentChange(val) {
      this.page = val;
      this.getList();
    },
    //隐藏新增表单
    hideTotas() {
      this.addFormVisible = false;
      this.filters.staffName = "";
      this.page = 1;
      this.getList();
    },
    //点击新增
    addCompany() {
      this.sendFormData = {};
      this.addFormVisible = true;
    },
    //点击查询
    findList() {
      this.page = 1;
      this.getList();
    },
    //获取员工列表
    getList() {
      let para = {
        staffName: this.filters.staffName,
        page: {
          page: this.page,
          pageSize: 10
        }
      };
      this.listLoading = true;
      staffList(para).then(res => {
        this.listLoading = false;
        this.list = res.records;
        this.total = res.total;
      });
    }
  },
  mounted() {
    this.getList();
  }
};
</script>
<style lang="less" scoped>
</style>
